﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Steamrunner
{
    class GuiManager : DrawableGameComponent
    {
        List<Button> buttons = new List<Button>();

        int currentIndex;

        public int CurrentIndex
        {
            get { return currentIndex; }
            set { currentIndex = value; }
        }

        public GuiManager(Game game)
            : base(game)
        {
        }

        public override void Initialize()
        {
            foreach (Button button in buttons)
            {
                button.Initialize();
            }

            if (buttons.Count > 0)
            {
                currentIndex = 0;
                buttons[currentIndex].State = (int)Enums.ButtonState.HOVER;
            }
            
            base.Initialize();
        }

        public void AddButton(Button button)
        {
            buttons.Add(button);
        }

        public void RemoveButton(Button button)
        {
            buttons.Remove(button);
        }

        public void JoystickDown()
        {
            buttons[currentIndex].State = (int)Enums.ButtonState.NORMAL;

            currentIndex++;
            if (currentIndex == buttons.Count)
            {
                currentIndex = 0;
            }

            buttons[currentIndex].State = (int)Enums.ButtonState.HOVER;
        }

        public void JoystickUp()
        {
            buttons[currentIndex].State = (int)Enums.ButtonState.NORMAL;

            currentIndex--;
            if (currentIndex == -1)
            {
                currentIndex = buttons.Count - 1;
            }

            buttons[currentIndex].State = (int)Enums.ButtonState.HOVER;
        }

        public string ButtonClicked()
        {
            return buttons[currentIndex].ChangeToScreen;
        }

        public override void Draw(GameTime gameTime)
        {
            foreach (Button button in buttons)
            {
                button.Draw(gameTime);
            }
        }
    }
}
